<?php
class Seo extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct() {
		$this->cache = new Ecore_Cache();
		$this->clear = $this->cache->clear;
	}
	public function getAll($intOff, $intLimit, &$intTotal) {
		try {						
			$this->prepare('call seos_getall(?,?)');		
			$this->bindParam(1, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intLimit, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Seo::getAll - ' .$e->getMessage());			
			return null;
		}
	}
	public function get($intSeoId) {
		try {						
			$this->prepare('call seos_get(?)');		
			$this->bindParam(1, $intSeoId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Seo::get - ' .$e->getMessage());			
			return null;
		}
	}
	public function add($intAdminId, $strController, $strAction, $strName, $strTitle, $strKeywords, $strDescription, $intLanguage=LANGUAGE_VN) {
		try {
			$this->prepare('call seos_add(?,?,?,?,?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $strController, PDO::PARAM_STR, 50);
			$this->bindParam(3, $strAction, PDO::PARAM_STR, 50);
			$this->bindParam(4, $strName, PDO::PARAM_STR, 100);
			$this->bindParam(5, $strTitle, PDO::PARAM_STR, 100);
			$this->bindParam(6, $strKeywords, PDO::PARAM_STR, 255);
			$this->bindParam(7, $strDescription, PDO::PARAM_STR, 255);
			$this->bindParam(8, $intLanguage, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Seo::add - ' . $e->getMessage());
			return null;
		}
	}	
	public function update($intAdminId, $intSeoId, $strName, $strTitle, $strKeywords, $strDescription, $intLanguage=LANGUAGE_VN) {
		try {
			$this->prepare('call seos_update(?,?,?,?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intSeoId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strName, PDO::PARAM_STR, 100);
			$this->bindParam(4, $strTitle, PDO::PARAM_STR, 100);
			$this->bindParam(5, $strKeywords, PDO::PARAM_STR, 255);
			$this->bindParam(6, $strDescription, PDO::PARAM_STR, 255);
			$this->bindParam(7, $intLanguage, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$strController 	= isset($arrResult[0]['controller']) ? $arrResult[0]['controller'] : 'index';
				$strAction	 	= isset($arrResult[0]['action']) ? $arrResult[0]['action'] : 'index';				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Seo::update - ' . $e->getMessage());
			return null;
		}
	}	
}